<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Ping 数据库连接</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.pg-get-notify" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">pg_get_notify</h1>
    <p class="verinfo">(PHP 4 &gt;= 4.3.0, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">pg_get_notify</span> &mdash; <span class="dc-title">Ping 数据库连接</span></p>

   </div>
   <div class="refsect1 unknown-seealsp" id="refsect1-function.pg-get-notify-unknown-seealsp">
    <h3 class="title">说明</h3>
     <div class="methodsynopsis dc-description">
      <span class="methodname"><strong>pg_get_notify</strong></span>
       ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$connection</code></span>
      [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$result_type</code></span>
     ] ) : <span class="type">array</span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>pg_get_notify()</strong></span> 取得 SQL 命令
     <em>NOTIFY</em>
     发送的通告消息。要接收通告消息，必须发送 SQL 命令
     <em>LISTEN</em>。如果连接中有通告消息，则数组包含消息名并且返回后端的
     PID。如果没有消息则返回 <strong><code>FALSE</code></strong>。
    </p>
    <p class="para">
     参见 <span class="function"><a href="pg_get_pid.html" class="function">pg_get_pid()</a></span>。
    </p>
    <p class="para">
     <div class="example" id="example-2498">
      <p><strong>Example #1 PostgreSQL NOTIFY 消息</strong></p>
      <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;<br />$conn&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_pconnect</span><span style="color: #007700">(</span><span style="color: #DD0000">"dbname=publisher"</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$conn</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"An&nbsp;error&nbsp;occured.\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;exit;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;Listen&nbsp;'author_updated'&nbsp;message&nbsp;from&nbsp;other&nbsp;processes<br /></span><span style="color: #0000BB">pq_query</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'LISTEN&nbsp;author_updated;'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$notify&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pg_get_notify</span><span style="color: #007700">(</span><span style="color: #0000BB">$conn</span><span style="color: #007700">);<br />if&nbsp;(!</span><span style="color: #0000BB">$notify</span><span style="color: #007700">)<br />&nbsp;&nbsp;&nbsp;&nbsp;print(</span><span style="color: #DD0000">"No&nbsp;messages\n"</span><span style="color: #007700">);<br />else<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$notify</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
      </div>

     </div>
    </p>
   </div>

  </div></div></div></body></html>